package com.hui.security.plugin;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.Properties;

/**
 * <b><code>DataRuleColumnPlugin</code></b>
 * <p/>
 * Description: 列级数据权限控制
 * <p/>
 * <b>Creation Time:</b> 2019/1/15 16:24.
 *
 * @author Hu weihui
 */
/*@Component
@Intercepts(
        @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = Statement.class)
)*/
@Slf4j
public class DataRuleColumnPlugin implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        ResultSetHandler resultSetHandler = (ResultSetHandler) invocation.getTarget();

        Field mappedStatementField = ReflectionUtils.findField(ResultSetHandler.class, "mappedStatement");

        MappedStatement mappedStatement = (MappedStatement) mappedStatementField.get(resultSetHandler);

        return null;
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }


    @Override
    public void setProperties(Properties properties) {

    }
}
